using System.Linq;
using Gw2Api;

namespace Gw2Overlay
{
    public class Util
    {

        public static string GetSpokenObjectiveName(Objective objective, NamingConvention namingConvention)
        {
            string[] components = objective.tag.Split("-".ToCharArray());
            if (components[0] == "EB")
            {
                return objective.name;
            }
            switch (namingConvention)
            {
                case NamingConvention.Cardinal:
                    return GetCardinalDirection(components[1]) + " " + components[2];
                case NamingConvention.CardinalExceptKeeps:
                    if (components[2] == "Keep")
                    {
                        return objective.name.Split(" ".ToCharArray()).Last();
                    }
                    else
                    {
                        return GetCardinalDirection(components[1]) + " " + components[2];
                    }
                case NamingConvention.Names:
                default:
                    return objective.name;
            }
        }

        private static string GetCardinalDirection(string abbr)
        {
            switch (abbr)
            {
                case "N":
                    return "North";
                case "NE":
                    return "North-East";
                case "NW":
                    return "North-West";
                case "E":
                    return "East";
                case "W":
                    return "West";
                case "SE":
                    return "South-East";
                case "SW":
                    return "South-West";
                case "S":
                    return "South";
                case "C":
                    return "Central";
                default:
                    return "";
            }
        }

        public static string GetSpokenWorldName(WvWApi api, string matchupId, string color, SpokenWorldNames spokenWorldNames)
        {
            if (spokenWorldNames == SpokenWorldNames.Names)
            {
                return Gw2WvWMapControl.Util.GetWorldName(api, matchupId, color);
            }
            else
            {
                return color;
            }
        }

        public static string GetSpokenMapName(WvWApi api, string matchupID, Objective objective, SpokenWorldNames spokenWorldNames)
        {
            switch (objective.map_type)
            {
                case WvWMaps.Center:
                    return "Eternal Battlegrounds";
                case WvWMaps.RedHome:
                    return GetSpokenWorldName(api, matchupID, "red", spokenWorldNames) + " Borderlands";
                case WvWMaps.GreenHome:
                    return GetSpokenWorldName(api, matchupID, "green", spokenWorldNames) + " Borderlands";
                case WvWMaps.BlueHome:
                    return GetSpokenWorldName(api, matchupID, "blue", spokenWorldNames) + " Borderlands";
                default:
                    return "";
            }
        }
    }
}